package br.org.groupware_workbench.collablet.news;

import java.util.List;

import br.org.groupware_workbench.collablet.news.internal.NewsDAO;
import br.org.groupware_workbench.collabletFw.facade.CollabletInstance;
import br.org.groupware_workbench.coreutils.DAOFactory;

public class NewsMgrInstance extends CollabletInstance {

    private final NewsDAO newsDAO = DAOFactory.get(NewsDAO.class);
    private int numRelatedNews = 3; // TODO: Não é thread-safe.

    public NewsMgrInstance() {
        super();
    }

    @Override
    public void init() {
        //this.newsDAO.copyFromAUN(this.getId());
    }

    @Override
    public void destroy() {
    	this.newsDAO.deleteByIdInstance(this.getId());
    }

    public void copyFromAUN(long id) {
        this.newsDAO.copyFromAUN(id);
    }
    
    public List<News> list() {
        return this.newsDAO.listByIdInstance(this.getId());
    }

    public News findById(long id) {
        return this.newsDAO.findById(id);
    }

    public void save(News news) {
        news.setIdInstance(this.getId());
        //this.newsDAO.copyFromAUN(news);
        this.newsDAO.save(news, true);  
    }

    public void delete(Long id) {
        this.newsDAO.deleteById(id);
    }
    
    public int getNumRelatedNews() {
        return numRelatedNews;
    }

    public void setNumRelatedNews(int numRelatedNews) {
        this.numRelatedNews = numRelatedNews;
    }
}
